package com.htht.job.executor.core.config;

import com.htht.job.executor.model.registry.Registry;
import com.htht.job.executor.service.registry.RegistryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * Created by zzj on 2018/1/30.
 */
@Component
public class RegistryConfig  implements ApplicationRunner {
    @Autowired
    private RegistryService registryService;
    @Value("${xxl.job.executor.appname}")
    private String appname;

    @Value("${xxl.job.executor.ip}")
    private String ip;

    @Value("${xxl.job.executor.port}")
    private String port;

    @Value("${mqDestination}")
    String mqDestination;

    @Value("${mqConcurrency}")
    int mqConcurrency;
    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {
        Registry registry=new Registry();
        registry.setRegistryKey(appname);
        registry.setRegistryIp(ip);
        registry.setPort(port);
        registry.setMqDestination(mqDestination);
        registry.setMqConcurrency(mqConcurrency);
        registryService.saveOrUpdate(registry);
    }
}
